/*
 * @Author: Jone XIn
 * @Date: 2022-01-10 21:48:40
 * @LastEditTime: 2022-01-28 21:02:56
 * @Description: Project model
 */
'use strict'

const { DataTypes, Model, Op } = require('sequelize');
class Project extends Model { }
const { db_config } = require('../config.json');
const dbInstance = require('../db/db');
const ProjectSeq = dbInstance.getSequelizeInstance(db_config);


Project.init(
    {
        uid: {
            autoIncrement: true,
            type: DataTypes.INTEGER,
            allowNull: false,
            primaryKey: true
        },
        sync_id: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        project_name: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        project_path: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        m_id: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        gen_time: {
            type: DataTypes.STRING,
            allowNull: true,
        },
    },
    {
        freezeTableName: true,
        sequelize: ProjectSeq,
        modelName: 'Project',
        timestamps: false
    }
)


Project.deleteOfflineList = async (keyList) => {
    return await Project.destroy({
        where: {
            [Op.or]: keyList.map(con_key => { con_key })
        }
    })
}

module.exports = {
    Project
};